Edit Profile Dialog: Fix "Smooth fonts" preview

Summary:
`setStyleHint()` resets `styleStrategy` (which has information about
font smoothing) when the second argument is missing.

Test Plan:
* {nav Settings > Edit current profile... > Appearance}
* Unselect/select "Smooth fonts" checkbox

**Actual result:** text rendering in the main terminal window does not
change.
**Expected result:** text rendering in the main terminal window should
use smoothing or not, depending on the checkbox state. The option change
should be visible instantly, without clicking OK or Apply.

Reviewers: #konsole, hindenburg

Reviewed By: #konsole, hindenburg

Subscribers: hindenburg, konsole-devel

Tags: #konsole

Differential Revision: https://phabricator.kde.org/D16361
wilder-portage
Mariusz Glebocki 8 years ago committed by Kurt Hindenburg
parent 4e09f089f9
commit 383434b3a9
  1. 1
      src/EditProfileDialog.cpp
  2. 37
      src/TerminalDisplay.cpp

@ -624,6 +624,7 @@ void EditProfileDialog::setAntialiasText(bool enable)
// update preview to reflect text smoothing state
fontSelected(profileFont);
preview(Profile::AntiAliasFonts, enable);
updateTempProfileProperty(Profile::AntiAliasFonts, enable);
}

@ -240,10 +240,7 @@ void TerminalDisplay::fontChange(const QFont&)
void TerminalDisplay::setVTFont(const QFont& f)
{
QFont newFont(f);
// In case the provided font doesn't have some specific characters it should
// fall back to a Monospace fonts.
newFont.setStyleHint(QFont::TypeWriter);
int strategy = 0;
QFontMetrics fontMetrics(newFont);
@ -257,38 +254,38 @@ void TerminalDisplay::setVTFont(const QFont& f)
return;
}
// hint that text should be drawn without anti-aliasing.
// hint that text should be drawn with- or without anti-aliasing.
// depending on the user's font configuration, this may not be respected
if (!_antialiasText) {
newFont.setStyleStrategy(QFont::StyleStrategy(newFont.styleStrategy() | QFont::NoAntialias));
}
// experimental optimization. Konsole assumes that the terminal is using a
// mono-spaced font, in which case kerning information should have an effect.
// Disabling kerning saves some computation when rendering text.
newFont.setKerning(false);
strategy |= _antialiasText ? QFont::PreferAntialias : QFont::NoAntialias;
// Konsole cannot handle non-integer font metrics
newFont.setStyleStrategy(QFont::StyleStrategy(newFont.styleStrategy() | QFont::ForceIntegerMetrics));
strategy |= QFont::ForceIntegerMetrics;
// In case the provided font doesn't have some specific characters it should
// fall back to a Monospace fonts.
newFont.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(strategy));
// Try to check that a good font has been loaded.
// For some fonts, ForceIntegerMetrics causes height() == 0 which
// will cause Konsole to crash later.
QFontMetrics fontMetrics2(newFont);
if ((fontMetrics2.height() < 1)) {
if (fontMetrics2.height() < 1) {
qCDebug(KonsoleDebug)<<"The font "<<newFont.toString()<<" has an invalid height()";
// Ask for a generic font so at least it is usable.
// Font listed in profile's dialog will not be updated.
newFont = QFont(QStringLiteral("Monospace"));
newFont.setStyleHint(QFont::TypeWriter);
// Set style strategy without ForceIntegerMetrics for the font
strategy &= ~QFont::ForceIntegerMetrics;
newFont.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(strategy));
qCDebug(KonsoleDebug)<<"Font changed to "<<newFont.toString();
}
QFontInfo fontInfo(newFont);
// experimental optimization. Konsole assumes that the terminal is using a
// mono-spaced font, in which case kerning information should have an effect.
// Disabling kerning saves some computation when rendering text.
newFont.setKerning(false);
// if (!fontInfo.fixedPitch()) {
// qWarning() << "Using a variable-width font - this might cause display problems";
// }
QFontInfo fontInfo(newFont);
// QFontInfo::fixedPitch() appears to not match QFont::fixedPitch()
// related? https://bugreports.qt.io/browse/QTBUG-34082

Loading…
Cancel
Save