File Fix-bold-font.patch of Package konsole
From 41693fe9ee263f8f2281852a740ee52d55f003ef Mon Sep 17 00:00:00 2001
From: Mariusz Glebocki <mglb@arccos-1.net>
Date: Sat, 23 Feb 2019 22:30:18 -0500
Subject: Fix "Draw intense colors in bold font" feature
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Summary:
Make the feature work and improve it slightly - the weight used as bold
is dependent on selected font's weight. "Regular" will use "Bold", but
e.g. "Thin" will use "Light".
`styleName` is almost always redundant - all font properties like
weight, stretch, etc, are stored separately.
Source Code Pro 12pt with font weight set to: Extra Light, Light,
Regular, Medium, Semibold, Bold:
{F6631951}
Test Plan:
In every case: turn on "Draw intense colors in bold font" in Edit
Profile → Appearance.
**The feature:**
* Use some font which has "Bold" style available and set it to "Regular"
style.
* Run: `printf '\033[1mBold|\033[0m|Normal\n'`
* "Bold|" text should use bold font.
**Different weights:**
* Use some font which has multiple weights available (e.g. Thin, Bold,
Heavy, ...), e.g. Source Code Pro.
* Select lightest style.
* Run: `printf '\033[1mBold|\033[0m|Normal\n'`
* Select "regular" font style.
* Bold text for "regular" style should be bolder than the text for
lightest style should be.
Reviewers: #konsole, #vdg, hindenburg
Reviewed By: #konsole, hindenburg
Subscribers: hindenburg, ngraham, konsole-devel
Tags: #konsole
Differential Revision: https://phabricator.kde.org/D19266
---
src/TerminalDisplay.cpp | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp
index 140ecfb..31bbacc 100644
--- a/src/TerminalDisplay.cpp
+++ b/src/TerminalDisplay.cpp
@@ -297,6 +297,11 @@ void TerminalDisplay::setVTFont(const QFont& f)
// Disabling kerning saves some computation when rendering text.
newFont.setKerning(false);
+ // "Draw intense colors in bold font" feature needs to use different font weights. StyleName
+ // property, when set, doesn't allow weight changes. Since all properties (weight, stretch,
+ // italic, etc) are stored in QFont independently, in almost all cases styleName is not needed.
+ newFont.setStyleName(QString());
+
QFontInfo fontInfo(newFont);
// QFontInfo::fixedPitch() appears to not match QFont::fixedPitch()
@@ -740,25 +745,32 @@ void TerminalDisplay::drawCharacters(QPainter& painter,
return;
}
- // setup bold and underline
- bool useBold = (((style->rendition & RE_BOLD) != 0) && _boldIntense) || font().bold();
+ 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 auto isBold = [boldWeight](const QFont &font) { return font.weight() >= boldWeight; };
+
+ const bool useBold = (((style->rendition & RE_BOLD) != 0) && _boldIntense);
const bool useUnderline = ((style->rendition & RE_UNDERLINE) != 0) || font().underline();
const bool useItalic = ((style->rendition & RE_ITALIC) != 0) || font().italic();
const bool useStrikeOut = ((style->rendition & RE_STRIKEOUT) != 0) || font().strikeOut();
const bool useOverline = ((style->rendition & RE_OVERLINE) != 0) || font().overline();
- QFont font = painter.font();
- if (font.bold() != useBold
- || font.underline() != useUnderline
- || font.italic() != useItalic
- || font.strikeOut() != useStrikeOut
- || font.overline() != useOverline) {
- font.setBold(useBold);
- font.setUnderline(useUnderline);
- font.setItalic(useItalic);
- font.setStrikeOut(useStrikeOut);
- font.setOverline(useOverline);
- painter.setFont(font);
+ QFont currentFont = painter.font();
+
+ if (isBold(currentFont) != useBold
+ || currentFont.underline() != useUnderline
+ || currentFont.italic() != useItalic
+ || currentFont.strikeOut() != useStrikeOut
+ || currentFont.overline() != useOverline) {
+ currentFont.setWeight(useBold ? boldWeight : normalWeight);
+ currentFont.setUnderline(useUnderline);
+ currentFont.setItalic(useItalic);
+ currentFont.setStrikeOut(useStrikeOut);
+ currentFont.setOverline(useOverline);
+ painter.setFont(currentFont);
}
// setup pen
--
cgit v1.1