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
wilder-portage
Mariusz Glebocki 7 years ago committed by Kurt Hindenburg
parent d77e3449ee
commit 41693fe9ee
  1. 40
      src/TerminalDisplay.cpp

@ -297,6 +297,11 @@ void TerminalDisplay::setVTFont(const QFont& f)
// Disabling kerning saves some computation when rendering text. // Disabling kerning saves some computation when rendering text.
newFont.setKerning(false); 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 fontInfo(newFont);
// QFontInfo::fixedPitch() appears to not match QFont::fixedPitch() // QFontInfo::fixedPitch() appears to not match QFont::fixedPitch()
@ -740,25 +745,32 @@ void TerminalDisplay::drawCharacters(QPainter& painter,
return; return;
} }
// setup bold and underline const int normalWeight = font().weight();
bool useBold = (((style->rendition & RE_BOLD) != 0) && _boldIntense) || font().bold(); // +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 useUnderline = ((style->rendition & RE_UNDERLINE) != 0) || font().underline();
const bool useItalic = ((style->rendition & RE_ITALIC) != 0) || font().italic(); const bool useItalic = ((style->rendition & RE_ITALIC) != 0) || font().italic();
const bool useStrikeOut = ((style->rendition & RE_STRIKEOUT) != 0) || font().strikeOut(); const bool useStrikeOut = ((style->rendition & RE_STRIKEOUT) != 0) || font().strikeOut();
const bool useOverline = ((style->rendition & RE_OVERLINE) != 0) || font().overline(); const bool useOverline = ((style->rendition & RE_OVERLINE) != 0) || font().overline();
QFont font = painter.font(); QFont currentFont = painter.font();
if (font.bold() != useBold
|| font.underline() != useUnderline if (isBold(currentFont) != useBold
|| font.italic() != useItalic || currentFont.underline() != useUnderline
|| font.strikeOut() != useStrikeOut || currentFont.italic() != useItalic
|| font.overline() != useOverline) { || currentFont.strikeOut() != useStrikeOut
font.setBold(useBold); || currentFont.overline() != useOverline) {
font.setUnderline(useUnderline); currentFont.setWeight(useBold ? boldWeight : normalWeight);
font.setItalic(useItalic); currentFont.setUnderline(useUnderline);
font.setStrikeOut(useStrikeOut); currentFont.setItalic(useItalic);
font.setOverline(useOverline); currentFont.setStrikeOut(useStrikeOut);
painter.setFont(font); currentFont.setOverline(useOverline);
painter.setFont(currentFont);
} }
// setup pen // setup pen

Loading…
Cancel
Save