fix #75816 : Implement space management for formatted text

This commit is contained in:
lasconic 2016-04-15 15:49:01 +02:00
parent 7005b1037c
commit ecfd7f2d09
3 changed files with 54 additions and 2 deletions

View file

@ -704,8 +704,7 @@ QString XmlReader::readXml()
case QXmlStreamReader::EndElement:
return s;
case QXmlStreamReader::Characters:
if (!isWhitespace() || text().toString() == "\n")
s += text().toString().toHtmlEscaped();
s += text().toString().toHtmlEscaped();
break;
case QXmlStreamReader::Comment:
break;

View file

@ -16,6 +16,7 @@
#include "libmscore/text.h"
#include "libmscore/score.h"
#include "libmscore/sym.h"
#include "libmscore/xml.h"
#include "mtest/testutils.h"
using namespace Ms;
@ -36,6 +37,7 @@ class TestText : public QObject, public MTest
void testTextProperties();
void testCompatibility();
void testDelete();
void testReadWrite();
};
//---------------------------------------------------------
@ -368,6 +370,53 @@ void TestText::testCompatibility()
QCOMPARE(text->convertFromHtml(sescape), QString("<font face=\"Times New Roman\"/>test&amp;&lt;&gt;&quot;'"));
}
//---------------------------------------------------------
/// testReadWrite
//---------------------------------------------------------
void TestText::testReadWrite() {
auto testrw = [](Score* score, Text* t) {
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
Xml xml(&buffer);
t->write(xml);
buffer.close();
XmlReader e(buffer.buffer());
Text* text2 = new Text(score);
e.readNextStartElement();
text2->read(e);
QCOMPARE(t->xmlText(), text2->xmlText());
};
Text* text = new Text(score);
text->setXmlText("test");
testrw(score, text);
text = new Text(score);
text->setXmlText("<b>Title</b><i>two</i>");
testrw(score, text);
text = new Text(score);
text->setXmlText("<i>Title</i> <b>Two</b>");
testrw(score, text);
text = new Text(score);
text->setXmlText("<i>Title</i> <b>Two</b>");
testrw(score, text);
text = new Text(score);
text->setXmlText("<i>Title</i>\t<b>Two</b>");
testrw(score, text);
text = new Text(score);
text->setXmlText("<i>Title</i>\n<b>Two</b>");
testrw(score, text);
text = new Text(score);
text->setXmlText("<i>Ti tle</i><b>Tw o</b>");
testrw(score, text);
}
QTEST_MAIN(TestText)
#include "tst_text.moc"

View file

@ -53,6 +53,10 @@
</Staff>
<trackName>Voice</trackName>
<Instrument>
<longName>
</longName>
<shortName>
</shortName>
<trackName>Voice</trackName>
<minPitchP>36</minPitchP>
<maxPitchP>94</maxPitchP>