Skip to content

Commit

Permalink
Properly deal with </font>
Browse files Browse the repository at this point in the history
instead of ignoring it altogether, reset font face and -size back to what it was before `<font ...>`.
While at it add the tags for strikeout, as possible in Mu4 already.

Also fix some code warnings shown by QtCreator.
  • Loading branch information
Jojo-Schmitz committed Mar 23, 2024
1 parent 9192de5 commit 298cf1c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions libmscore/textbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
// the file LICENCE.GPL
//=============================================================================

#include "text.h"
#include "textedit.h"
#include "jump.h"
#include "marker.h"
#include "score.h"
#include "segment.h"
#include "measure.h"
Expand Down Expand Up @@ -1264,7 +1261,6 @@ QString TextBlock::remove(int column, TextCursor* cursor)
QString s;
for (auto i = _fragments.begin(); i != _fragments.end(); ++i) {
int idx = 0;
int rcol = 0;
for (const QChar& c : qAsConst(i->text)) {
if (col == column) {
if (c.isSurrogate()) {
Expand All @@ -1285,7 +1281,6 @@ QString TextBlock::remove(int column, TextCursor* cursor)
if (c.isHighSurrogate())
continue;
++col;
++rcol;
}
}
insertEmptyFragmentIfNeeded(cursor); // without this, cursorRect can't calculate the y position of the cursor correctly
Expand Down Expand Up @@ -1326,7 +1321,6 @@ QString TextBlock::remove(int start, int n, TextCursor* cursor)
int col = 0;
QString s;
for (auto i = _fragments.begin(); i != _fragments.end();) {
int rcol = 0;
bool inc = true;
for( int idx = 0; idx < i->text.length(); ) {
QChar c = i->text[idx];
Expand All @@ -1353,7 +1347,6 @@ QString TextBlock::remove(int start, int n, TextCursor* cursor)
if (c.isHighSurrogate())
continue;
++col;
++rcol;
}
if (inc)
++i;
Expand Down Expand Up @@ -1697,6 +1690,8 @@ void TextBase::createLayout()
}
else if (state == 1) {
if (c == '>') {
static QString prevFontFace;
static qreal prevFontSize = 0;
bool unstyleFontStyle = false;
state = 0;
if (token == "b") {
Expand All @@ -1717,6 +1712,12 @@ void TextBase::createLayout()
}
else if (token == "/u")
cursor.format()->setUnderline(false);
else if (token == "s") {
cursor.format()->setStrike(true);
unstyleFontStyle = true;
}
else if (token == "/s")
cursor.format()->setStrike(false);
else if (token == "sub")
cursor.format()->setValign(VerticalAlignment::AlignSubScript);
else if (token == "/sub")
Expand Down Expand Up @@ -1749,19 +1750,31 @@ void TextBase::createLayout()
else if (token.startsWith("font ")) {
token = token.mid(5);
if (token.startsWith("size=\"")) {
prevFontSize = cursor.format()->fontSize();
cursor.format()->setFontSize(parseNumProperty(token.mid(6)));
setPropertyFlags(Pid::FONT_SIZE, PropertyFlags::UNSTYLED);
}
else if (token.startsWith("face=\"")) {
QString face = parseStringProperty(token.mid(6));
face = unEscape(face);
prevFontFace = cursor.format()->fontFamily();
cursor.format()->setFontFamily(face);
setPropertyFlags(Pid::FONT_FACE, PropertyFlags::UNSTYLED);
}
else
qDebug("cannot parse html property <%s> in text <%s>",
qPrintable(token), qPrintable(_text));
}
else if ( token == "/font" ) {
if (prevFontSize) {
cursor.format()->setFontSize(prevFontSize);
prevFontSize = 0;
}
if (!prevFontFace.isEmpty()) {
cursor.format()->setFontFamily(prevFontFace);
prevFontFace = "";
}
}
if (unstyleFontStyle)
setPropertyFlags(Pid::FONT_STYLE, PropertyFlags::UNSTYLED);
}
Expand Down

0 comments on commit 298cf1c

Please sign in to comment.