Changeset View
Changeset View
Standalone View
Standalone View
src/TerminalDisplay.cpp
Show First 20 Lines • Show All 234 Lines • ▼ Show 20 Line(s) | 207 | { | |||
---|---|---|---|---|---|
235 | emit changedFontMetricSignal(_fontHeight, _fontWidth); | 235 | emit changedFontMetricSignal(_fontHeight, _fontWidth); | ||
236 | propagateSize(); | 236 | propagateSize(); | ||
237 | update(); | 237 | update(); | ||
238 | } | 238 | } | ||
239 | 239 | | |||
240 | void TerminalDisplay::setVTFont(const QFont& f) | 240 | void TerminalDisplay::setVTFont(const QFont& f) | ||
241 | { | 241 | { | ||
242 | QFont newFont(f); | 242 | QFont newFont(f); | ||
243 | 243 | int strategy = 0; | |||
244 | // In case the provided font doesn't have some specific characters it should | | |||
245 | // fall back to a Monospace fonts. | | |||
246 | newFont.setStyleHint(QFont::TypeWriter); | | |||
247 | 244 | | |||
248 | QFontMetrics fontMetrics(newFont); | 245 | QFontMetrics fontMetrics(newFont); | ||
249 | 246 | | |||
250 | // This check seems extreme and semi-random | 247 | // This check seems extreme and semi-random | ||
251 | // TODO: research if these checks are still needed to prevent | 248 | // TODO: research if these checks are still needed to prevent | ||
252 | // enormous fonts from being used; consider usage on big TV | 249 | // enormous fonts from being used; consider usage on big TV | ||
253 | // screens. | 250 | // screens. | ||
254 | if ((fontMetrics.height() > height()) || (fontMetrics.maxWidth() > width())) { | 251 | if ((fontMetrics.height() > height()) || (fontMetrics.maxWidth() > width())) { | ||
255 | // return here will cause the "general" non-fixed width font | 252 | // return here will cause the "general" non-fixed width font | ||
256 | // to be selected | 253 | // to be selected | ||
257 | return; | 254 | return; | ||
258 | } | 255 | } | ||
259 | 256 | | |||
260 | // hint that text should be drawn without anti-aliasing. | 257 | // hint that text should be drawn with- or without anti-aliasing. | ||
261 | // depending on the user's font configuration, this may not be respected | 258 | // depending on the user's font configuration, this may not be respected | ||
262 | if (!_antialiasText) { | 259 | strategy |= _antialiasText ? QFont::PreferAntialias : QFont::NoAntialias; | ||
263 | newFont.setStyleStrategy(QFont::StyleStrategy(newFont.styleStrategy() | QFont::NoAntialias)); | | |||
264 | } | | |||
265 | | ||||
266 | // experimental optimization. Konsole assumes that the terminal is using a | | |||
267 | // mono-spaced font, in which case kerning information should have an effect. | | |||
268 | // Disabling kerning saves some computation when rendering text. | | |||
269 | newFont.setKerning(false); | | |||
270 | 260 | | |||
271 | // Konsole cannot handle non-integer font metrics | 261 | // Konsole cannot handle non-integer font metrics | ||
272 | newFont.setStyleStrategy(QFont::StyleStrategy(newFont.styleStrategy() | QFont::ForceIntegerMetrics)); | 262 | strategy |= QFont::ForceIntegerMetrics; | ||
263 | | ||||
264 | // In case the provided font doesn't have some specific characters it should | ||||
265 | // fall back to a Monospace fonts. | ||||
266 | newFont.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(strategy)); | ||||
273 | 267 | | |||
274 | // Try to check that a good font has been loaded. | 268 | // Try to check that a good font has been loaded. | ||
275 | // For some fonts, ForceIntegerMetrics causes height() == 0 which | 269 | // For some fonts, ForceIntegerMetrics causes height() == 0 which | ||
276 | // will cause Konsole to crash later. | 270 | // will cause Konsole to crash later. | ||
277 | QFontMetrics fontMetrics2(newFont); | 271 | QFontMetrics fontMetrics2(newFont); | ||
278 | if ((fontMetrics2.height() < 1)) { | 272 | if (fontMetrics2.height() < 1) { | ||
279 | qCDebug(KonsoleDebug)<<"The font "<<newFont.toString()<<" has an invalid height()"; | 273 | qCDebug(KonsoleDebug)<<"The font "<<newFont.toString()<<" has an invalid height()"; | ||
280 | // Ask for a generic font so at least it is usable. | 274 | // Ask for a generic font so at least it is usable. | ||
281 | // Font listed in profile's dialog will not be updated. | 275 | // Font listed in profile's dialog will not be updated. | ||
282 | newFont = QFont(QStringLiteral("Monospace")); | 276 | newFont = QFont(QStringLiteral("Monospace")); | ||
283 | newFont.setStyleHint(QFont::TypeWriter); | 277 | // Set style strategy without ForceIntegerMetrics for the font | ||
278 | strategy &= ~QFont::ForceIntegerMetrics; | ||||
279 | newFont.setStyleHint(QFont::TypeWriter, QFont::StyleStrategy(strategy)); | ||||
284 | qCDebug(KonsoleDebug)<<"Font changed to "<<newFont.toString(); | 280 | qCDebug(KonsoleDebug)<<"Font changed to "<<newFont.toString(); | ||
285 | } | 281 | } | ||
286 | 282 | | |||
287 | QFontInfo fontInfo(newFont); | 283 | // experimental optimization. Konsole assumes that the terminal is using a | ||
284 | // mono-spaced font, in which case kerning information should have an effect. | ||||
285 | // Disabling kerning saves some computation when rendering text. | ||||
286 | newFont.setKerning(false); | ||||
288 | 287 | | |||
289 | // if (!fontInfo.fixedPitch()) { | 288 | QFontInfo fontInfo(newFont); | ||
290 | // qWarning() << "Using a variable-width font - this might cause display problems"; | | |||
291 | // } | | |||
292 | 289 | | |||
293 | // QFontInfo::fixedPitch() appears to not match QFont::fixedPitch() | 290 | // QFontInfo::fixedPitch() appears to not match QFont::fixedPitch() | ||
294 | // related? https://bugreports.qt.io/browse/QTBUG-34082 | 291 | // related? https://bugreports.qt.io/browse/QTBUG-34082 | ||
295 | if (!fontInfo.exactMatch()) { | 292 | if (!fontInfo.exactMatch()) { | ||
296 | const QChar comma(QLatin1Char(',')); | 293 | const QChar comma(QLatin1Char(',')); | ||
297 | QString nonMatching = fontInfo.family() % comma % | 294 | QString nonMatching = fontInfo.family() % comma % | ||
298 | QString::number(fontInfo.pointSizeF()) % comma % | 295 | QString::number(fontInfo.pointSizeF()) % comma % | ||
299 | QString::number(fontInfo.pixelSize()) % comma % | 296 | QString::number(fontInfo.pixelSize()) % comma % | ||
▲ Show 20 Lines • Show All 3661 Lines • Show Last 20 Lines |