From 5e91383e3fc942ae6c86aeb01d281e59be5ae125 Mon Sep 17 00:00:00 2001 From: Mariusz Glebocki Date: Tue, 1 Oct 2019 21:26:38 +0200 Subject: [PATCH] Make sure font weight value is within allowed range --- src/TerminalDisplay.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp index 727d49c3..5753ae74 100644 --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -777,10 +777,12 @@ void TerminalDisplay::drawCharacters(QPainter& painter, return; } + static constexpr int MaxFontWeight = 99; // https://doc.qt.io/qt-5/qfont.html#Weight-enum + const int normalWeight = font().weight(); // +26 makes "bold" from "normal", "normal" from "light", etc. It is 26 instead of not 25 to prefer // bolder weight when 25 falls in the middle between two weights. See QFont::Weight - const int boldWeight = normalWeight + 26; + const int boldWeight = qMin(normalWeight + 26, MaxFontWeight); const auto isBold = [boldWeight](const QFont &font) { return font.weight() >= boldWeight; };