Skip to content

Commit

Permalink
Refactor TextBase::prepareFormat to avoid static
Browse files Browse the repository at this point in the history
  • Loading branch information
cbjeukendrup committed Mar 31, 2024
1 parent 662f6be commit 0f867ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/engraving/dom/textbase.cpp
Expand Up @@ -1792,6 +1792,10 @@ void TextBase::createBlocks(LayoutData* ldata) const
String token;
String sym;
bool symState = false;

String prevFontFace;
double prevFontSize = 0;

for (size_t i = 0; i < m_text.size(); i++) {
const Char& c = m_text.at(i);
if (state == 0) {
Expand Down Expand Up @@ -1841,7 +1845,7 @@ void TextBase::createBlocks(LayoutData* ldata) const
} else if (state == 1) {
if (c == '>') {
state = 0;
const_cast<TextBase*>(this)->prepareFormat(token, cursor);
const_cast<TextBase*>(this)->prepareFormat(token, cursor, prevFontFace, prevFontSize);
if (token == "sym") {
symState = true;
sym.clear();
Expand Down Expand Up @@ -1891,11 +1895,8 @@ void TextBase::createBlocks(LayoutData* ldata) const
//---------------------------------------------------------
// prepareFormat - used when reading from XML and when pasting from clipboard
//---------------------------------------------------------
bool TextBase::prepareFormat(const String& token, CharFormat& format)
bool TextBase::prepareFormat(const String& token, CharFormat& format, String& prevFontFace, double& prevFontSize) const
{
static String prevFontFace;
static double prevFontSize = 0;

if (token == "b") {
format.setBold(true);
return true;
Expand Down Expand Up @@ -1956,9 +1957,10 @@ bool TextBase::prepareFormat(const String& token, CharFormat& format)
//---------------------------------------------------------
// prepareFormat - used when reading from XML
//---------------------------------------------------------
void TextBase::prepareFormat(const String& token, TextCursor& cursor)
void TextBase::prepareFormat(const String& token, TextCursor& cursor, String& prevFontFace, double& prevFontSize)
{
if (prepareFormat(token, *cursor.format()) && cursor.format()->fontFamily() != propertyDefault(Pid::FONT_FACE).value<String>()) {
if (prepareFormat(token, *cursor.format(), prevFontFace, prevFontSize)
&& cursor.format()->fontFamily() != propertyDefault(Pid::FONT_FACE).value<String>()) {
setPropertyFlags(Pid::FONT_FACE, PropertyFlags::UNSTYLED);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/engraving/dom/textbase.h
Expand Up @@ -474,8 +474,8 @@ class TextBase : public EngravingItem
TextBase(const TextBase&);

void insertSym(EditData& ed, SymId id);
void prepareFormat(const String& token, TextCursor& cursor);
bool prepareFormat(const String& token, CharFormat& format);
void prepareFormat(const String& token, TextCursor& cursor, String& prevFontFace, double& prevFontSize);
bool prepareFormat(const String& token, CharFormat& format, String& prevFontFace, double& prevFontSize) const;

virtual void commitText();

Expand Down

0 comments on commit 0f867ec

Please sign in to comment.