forked from qt-creator/qt-creator
TextEditor: Avoid divide by zero error
And adding a few asserts in places that could cause this to happen. Fixes: QTCREATORBUG-31623 Change-Id: I8de5db14313791b1d6614dc0e29d0d3dd65e8542 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -103,6 +103,7 @@ bool FontSettings::fromSettings(const FormatDescriptions &descriptions, const Qt
|
||||
m_fontSize = s->value(group + fontSizeKey, m_fontSize).toInt();
|
||||
m_fontZoom= s->value(group + fontZoomKey, m_fontZoom).toInt();
|
||||
m_lineSpacing = s->value(group + lineSpacingKey, m_lineSpacing).toInt();
|
||||
QTC_ASSERT(m_lineSpacing >= 0, m_lineSpacing = 100);
|
||||
m_antialias = s->value(group + antialiasKey, DEFAULT_ANTIALIAS).toBool();
|
||||
|
||||
if (s->contains(group + schemeFileNamesKey)) {
|
||||
@@ -337,7 +338,7 @@ qreal FontSettings::lineSpacing() const
|
||||
QFont currentFont = font();
|
||||
currentFont.setPointSize(std::max(m_fontSize * m_fontZoom / 100, 1));
|
||||
qreal spacing = QFontMetricsF(currentFont).lineSpacing();
|
||||
if (m_lineSpacing != 100)
|
||||
if (QTC_GUARD(m_lineSpacing > 0) && m_lineSpacing != 100)
|
||||
spacing *= qreal(m_lineSpacing) / 100;
|
||||
return spacing;
|
||||
}
|
||||
|
@@ -5160,6 +5160,7 @@ void TextEditorWidgetPrivate::updateLineAnnotation(const PaintEventData &data,
|
||||
q->viewport()->update(annotationRect.rect.toAlignedRect());
|
||||
}
|
||||
m_annotationRects[data.block.blockNumber()] = newRects;
|
||||
QTC_ASSERT(data.lineSpacing != 0, return);
|
||||
const int maxVisibleLines = data.viewportRect.height() / data.lineSpacing;
|
||||
if (m_annotationRects.size() >= maxVisibleLines * 2)
|
||||
scheduleCleanupAnnotationCache();
|
||||
|
Reference in New Issue
Block a user