Skip to content

Commit

Permalink
Add a compatibility function to read obsolete text style properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrio95 committed Nov 27, 2018
1 parent e9e09fc commit 1a764fd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions libmscore/style.cpp
Expand Up @@ -2126,9 +2126,58 @@ bool MStyle::readStyleValCompat(XmlReader& e)
e.readElementText();
return true;
}
if (readTextStyleValCompat(e))
return true;
return false;
}

//---------------------------------------------------------
// readTextStyleValCompat
// Handle transition from separate bold, underline and
// italic style properties to the single *FontStyle
// property set.
//---------------------------------------------------------

bool MStyle::readTextStyleValCompat(XmlReader& e)
{
constexpr std::array<std::pair<const char*, FontStyle>, 3> styleNamesEndings {{
{ "FontBold", FontStyle::Bold },
{ "FontItalic", FontStyle::Italic },
{ "FontUnderline", FontStyle::Underline }
}};

const QStringRef tag(e.name());
FontStyle readFontStyle = FontStyle::Normal;
QStringRef typeName;
for (auto& fontStyle : styleNamesEndings) {
if (tag.endsWith(fontStyle.first)) {
readFontStyle = fontStyle.second;
typeName = tag.mid(0, tag.length() - strlen(fontStyle.first));
break;
}
}
if (readFontStyle == FontStyle::Normal)
return false;

const QString newFontStyleName = typeName.toString() + "FontStyle";
const Sid sid = MStyle::styleIdx(newFontStyleName);
if (sid == Sid::NOSTYLE) {
qWarning() << "readFontStyleValCompat: couldn't read text readFontStyle value:" << tag;
return false;
}

const bool readVal = bool(e.readElementText().toInt());
const QVariant val = value(sid);
FontStyle newFontStyle = (val == QVariant()) ? FontStyle::Normal : FontStyle(val.toInt());
if (readVal)
newFontStyle = newFontStyle + readFontStyle;
else
newFontStyle = newFontStyle - readFontStyle;

set(sid, int(newFontStyle));
return true;
}

//---------------------------------------------------------
// load
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/style.h
Expand Up @@ -1070,6 +1070,7 @@ class MStyle {
void save(XmlWriter& xml, bool optimize);
bool readProperties(XmlReader&);
bool readStyleValCompat(XmlReader&);
bool readTextStyleValCompat(XmlReader&);

void reset(Score*);

Expand Down

0 comments on commit 1a764fd

Please sign in to comment.