Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 41693fe9 authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg

Fix "Draw intense colors in bold font" feature

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
parent d77e3449
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment