forked from qt-creator/qt-creator
Editor: fix FontSettings::lineSpacing for zoomed fonts
Change-Id: Ia7ad3a877c56fb9cd962592b6d3e967beb9002dc Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -39,8 +39,7 @@ FontSettings::FontSettings() :
|
|||||||
m_fontSize(defaultFontSize()),
|
m_fontSize(defaultFontSize()),
|
||||||
m_fontZoom(100),
|
m_fontZoom(100),
|
||||||
m_lineSpacing(100),
|
m_lineSpacing(100),
|
||||||
m_antialias(DEFAULT_ANTIALIAS),
|
m_antialias(DEFAULT_ANTIALIAS)
|
||||||
m_lineSpacingCache(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +260,6 @@ void FontSettings::clearCaches()
|
|||||||
{
|
{
|
||||||
m_formatCache.clear();
|
m_formatCache.clear();
|
||||||
m_textCharFormatCache.clear();
|
m_textCharFormatCache.clear();
|
||||||
m_lineSpacingCache = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
|
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
|
||||||
@@ -337,17 +335,12 @@ void FontSettings::setFontZoom(int zoom)
|
|||||||
|
|
||||||
qreal FontSettings::lineSpacing() const
|
qreal FontSettings::lineSpacing() const
|
||||||
{
|
{
|
||||||
if (m_lineSpacing == 100) {
|
QFont currentFont = font();
|
||||||
QFontMetricsF fm(font());
|
currentFont.setPointSize(m_fontSize * m_fontZoom / 100);
|
||||||
return fm.lineSpacing();
|
qreal spacing = QFontMetricsF(currentFont).lineSpacing();
|
||||||
}
|
if (m_lineSpacing != 100)
|
||||||
|
spacing *= 100 / m_lineSpacing;
|
||||||
if (qFuzzyIsNull(m_lineSpacingCache)) {
|
return spacing;
|
||||||
auto currentFont = font();
|
|
||||||
currentFont.setPointSize(m_fontSize * m_fontZoom / 100);
|
|
||||||
m_lineSpacingCache = QFontMetricsF(currentFont).lineSpacing() / 100 * m_lineSpacing;
|
|
||||||
}
|
|
||||||
return m_lineSpacingCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FontSettings::relativeLineSpacing() const
|
int FontSettings::relativeLineSpacing() const
|
||||||
@@ -358,7 +351,6 @@ int FontSettings::relativeLineSpacing() const
|
|||||||
void FontSettings::setRelativeLineSpacing(int relativeLineSpacing)
|
void FontSettings::setRelativeLineSpacing(int relativeLineSpacing)
|
||||||
{
|
{
|
||||||
m_lineSpacing = relativeLineSpacing;
|
m_lineSpacing = relativeLineSpacing;
|
||||||
m_lineSpacingCache = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QFont FontSettings::font() const
|
QFont FontSettings::font() const
|
||||||
|
@@ -99,7 +99,6 @@ private:
|
|||||||
ColorScheme m_scheme;
|
ColorScheme m_scheme;
|
||||||
mutable QHash<TextStyle, QTextCharFormat> m_formatCache;
|
mutable QHash<TextStyle, QTextCharFormat> m_formatCache;
|
||||||
mutable QHash<TextStyles, QTextCharFormat> m_textCharFormatCache;
|
mutable QHash<TextStyles, QTextCharFormat> m_textCharFormatCache;
|
||||||
mutable qreal m_lineSpacingCache;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
Reference in New Issue
Block a user