Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify applying of bold and italic fonts #180

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions markdownhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ void MarkdownHighlighter::initTextFormats(int defaultFontSize) {
_formats[H5] = format;
format.setFontPointSize(defaultFontSize * 1.1);
_formats[H6] = format;
format.setFontPointSize(defaultFontSize);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was superfluous because the changed format is overridden by the next line.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the FontPointSize set?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, format = QTextCharFormat();, ok


// set character format for horizontal rulers
format = QTextCharFormat();
Expand Down Expand Up @@ -2430,13 +2429,7 @@ void MarkdownHighlighter::highlightEmAndStrong(const QString &text,
startDelim.marker == QLatin1Char('_');
while (k != (startDelim.pos + boldLen)) {
QTextCharFormat fmt = QSyntaxHighlighter::format(k);
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
fmt.setFontFamily(_formats[Bold].fontFamily());
#else
const QStringList fontFamilies = _formats[Bold].fontFamilies().toStringList();
if (!fontFamilies.isEmpty())
fmt.setFontFamilies(fontFamilies);
#endif
fmt.setFont(_formats[Bold].font(), QTextCharFormat::FontPropertiesSpecifiedOnly);

if (_formats[state].fontPointSize() > 0)
fmt.setFontPointSize(_formats[state].fontPointSize());
Expand All @@ -2446,10 +2439,8 @@ void MarkdownHighlighter::highlightEmAndStrong(const QString &text,
fmt.setForeground(_formats[Bold].foreground());
if (underline) {
fmt.setForeground(_formats[StUnderline].foreground());
fmt.setFont(_formats[StUnderline].font());
fmt.setFontUnderline(_formats[StUnderline].fontUnderline());
} else if (_formats[Bold].font().bold())
fmt.setFontWeight(QFont::Bold);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer necessary, because this is already covered by the setFont above.

fmt.setFont(_formats[StUnderline].font(), QTextCharFormat::FontPropertiesSpecifiedOnly);
}
setFormat(k, 1, fmt);
++k;
}
Expand Down Expand Up @@ -2479,14 +2470,7 @@ void MarkdownHighlighter::highlightEmAndStrong(const QString &text,
const int itLen = endDelim.pos - startDelim.pos;
while (k != (startDelim.pos + itLen)) {
QTextCharFormat fmt = QSyntaxHighlighter::format(k);

#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
fmt.setFontFamily(_formats[Italic].fontFamily());
#else
const QStringList fontFamilies = _formats[Italic].fontFamilies().toStringList();
if (!fontFamilies.isEmpty())
fmt.setFontFamilies(fontFamilies);
#endif
fmt.setFont(_formats[Italic].font(), QTextCharFormat::FontPropertiesSpecifiedOnly);

if (_formats[state].fontPointSize() > 0)
fmt.setFontPointSize(_formats[state].fontPointSize());
Expand All @@ -2496,8 +2480,6 @@ void MarkdownHighlighter::highlightEmAndStrong(const QString &text,

if (underline)
fmt.setFontUnderline(_formats[StUnderline].fontUnderline());
else
fmt.setFontItalic(_formats[Italic].fontItalic());
setFormat(k, 1, fmt);
++k;
}
Expand Down